<html>

<head>
    <!-- bootstrap 4.x is supported. You can also use the bootstrap css 3.3.x versions -->
    <link rel="stylesheet" href="/static/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/static/css/custom.css">
    <link href="/static/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />

    <script src="/static/js/jquery-3.2.1.min.js"></script>
    <script src="/static/js/popper.min.js"></script>
    <script src="/static/js/piexif.min.js" type="text/javascript"></script>
    <script src="/static/js/sortable.min.js" type="text/javascript"></script>
    <script src="/static/js/purify.min.js" type="text/javascript"></script>
    <script src="/static/js/popper.min.js"></script>
    <script src="/static/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/static/js/fileinput.min.js"></script>
    <script src="/static/js/theme.js"></script>
    <script src="/static/js/auth.js"></script>
    <title>文件上传</title>
</head>

<body class="home">
    <div class="home-title center">文件上传</div>
    <div class="container">
        <div class="row center">
            <div class="col-md-12">
                <form class="form-inline" id="upForm" action="#" method="post" enctype="multipart/form-data">
                    <div class="form-group">
                        <input id="file" type="file" class="form-control control" name="file" />
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-xs btn-primary btn-custom" onclick="onUpload();">
                            提交
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>

<script lang="javascript">
    function onUpload() {
        var upUrl = "/file/upload?" + queryParams();
        var upEntry = localStorage.getItem("uploadEntry");
        if (upEntry != "") {
            upUrl = "http://" + upEntry + "/file/upload?" + queryParams();
        }
        $.ajax({
            url: upUrl,
            type: 'POST',
            cache: false,
            data: new FormData($('#upForm')[0]),
            processData: false,
            contentType: false,
            error: function(err) {
                alert('请求报错信息: ' + JSON.stringify(err));
            },
            success: function(res) {
                alert('请求返回结果: ' + JSON.stringify(res));
                if (res.code == 0) {
                    window.location.href = "/static/view/home.html";
                }
            }
        });
    }
</script>

</html>